<?php

use app\admin\model\User;
use app\admin\service\interface\CacheService;
use PHPUnit\Framework\TestCase;
use think\App;
use think\facade\Cache;

use function PHPUnit\Framework\assertTrue;

class CacheTest extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        $http = (new App())->http;

        $response = $http->run();
    }
    function tearDown(): void
    {
        assertTrue(true);
    }
    public function testClear()
    {
        Cache::clear(); 
    }
    public function testCcc()
    {
        // Cache::set('name', ["aaaa","bbbb","cccc"]);
        // var_dump(CacheService::CACHE_CATEGORY);
        /**
         * @var app\admin\service\CacheServiceImpl
         */
        $cacheService=app("cacheService");
        $cacheService->init();
        invoke(function (CacheService $cacheService2) use ($cacheService) {
            $cacheService2->init();
            $cacheService->init();
            var_dump($cacheService===$cacheService2);
        });
    }
    public function testAa()
    {
        // 缓存在3600秒之后过期
        $obj= new stdClass();
        $obj->foo = "bar";
        $obj->bar = 222;
        $user = User::find(1);
        var_dump(json_encode($obj));
        Cache::set('name', ["aaaa","bbbb","cccc"]);
        Cache::set("obj", $obj,3600);
        Cache::set("obj2", json_encode($obj),3600);
        Cache::set("user", $user);
    }
    public function testBb()
    {
        // $name=Cache::get("name");
        // var_dump($name);
        $obj=Cache::get("obj");
        var_dump($obj);
        $obj2=Cache::get("obj2");
        var_dump($obj2);
        $user=Cache::get("user");
        var_dump($user->username);
        
    }
}
